<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>zio-ws-client</title>
		<script src="../zio-ws-client.js"></script>
		<style>
			#message p{
				width: 100%;
				word-wrap: break-word;
				word-break: normal;
			}
		</style>
	</head>
	<body>
		<div id="main">
			<button type="button" onclick="connect()">建立连接</button>
			<button type="button" onclick="removeListener()">移除监听器</button>
			<div id="message"></div>
		</div>
	</body>
	<script type="text/javascript">
		
		var myMulticaster = new zio.Multicaster("myMulticaster");
		
		var myListener = new zio.Listener("myListener",function(obj){
			console.log(obj);
		},zio.Events.OPEN,zio.Events.PING);
		
		myMulticaster.addListener(myListener);
		
		zio.addMulticaster(myMulticaster);
		
		//建立连接
		function connect() {
			zio.connect({
				url:"ws://localhost:9876",
				handler: {
					ping: function(obj) {
						obj._ws.send(JSON.stringify({
							// chatType: "heartbeat"
							cmd:1
						}))
					}
				}
			});
		}
		
		//移除监听器
		function removeListener(){
			myMulticaster.removeListener(myListener);
		}
	</script>
</html>
